package com.binarycube.webserver.wrappers;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.binarycube.webserver.session.Session;

public class WrappedSession extends Wrapper{

	Session session;
	
	public WrappedSession(Session session) {
		this.session = session;
	}
	
	public String getUser() {
		if (session != null) return session.getUID();
		return "";
	}

	public String getID(){
		if (session != null) return session.getID();
		return "";
	}

	public boolean isActive(){
		if (session != null) return session.isActive();
		return false;
	}


	public boolean isAnonymous(){
		if (session != null) return !session.isAuthenicated();
		return true;
	}

	public Date getCreated(){
		if (session != null) return session.getCreated();
		return null;
	}
	
	
	public Map<String,String> getProperties(){
		Map<String, String> tmp = new HashMap<String, String>();
		for (String key : session.getPropertyKeys()) {
			tmp.put(key, session.getProperty(key).toString());
		}
		return tmp;
	}
	
	public String getProperty(String key) {
		return session.getProperty(key).toString();
	}
	
	public void setProperty(String key, String value) {
		session.setProperty(key, value);
	}
	
}

